package com.example.androidsensors;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;

public class WarningDialogFragment extends DialogFragment{
	private String title = "";
	private String message = "";
	private String btnTitle = "";
	private int action;
	
	public void setDialog(String title, String message, String btnTitle, int action){
		this.title = title;
		this.message = message;
		this.btnTitle = btnTitle;
		this.action = action;
	}
	public void setDialog(String title, String message, String btnTitle){
		this.title = title;
		this.message = message;
		this.btnTitle = btnTitle;
		this.action = 0;
	}
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState){
		AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.MyTheme));
		
		builder.setTitle(this.title);
		if(action != 2 && action != 3) builder.setMessage(this.message);
		else {
			LayoutInflater inflater = getActivity().getLayoutInflater();
			if(action == 2) 
				builder.setView(inflater.inflate(R.layout.dialog_about, null));
			else if(action == 3)
				builder.setView(inflater.inflate(R.layout.dialog_help, null));
		}
			
		builder.setPositiveButton(this.btnTitle, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int id) {
						if(action == 1) startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
					}
				});
		return builder.create();
	}
}
